//
//  UseCAShapeLayerOnDrawingBoardView.m
//  CoreAnimation
//
//  Created by 张国文 on 16/11/1.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "UseCAShapeLayerOnDrawingBoardView.h"

@interface UseCAShapeLayerOnDrawingBoardView ()

@property (nonatomic, strong) UIBezierPath *bezierPath;

@end

@implementation UseCAShapeLayerOnDrawingBoardView

+(Class)layerClass
{
    return [CAShapeLayer class];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.bezierPath = [UIBezierPath bezierPath];
        CAShapeLayer *shapeLayer = (CAShapeLayer *)self.layer;
        shapeLayer.strokeColor = [UIColor redColor].CGColor;
        shapeLayer.fillColor = [UIColor clearColor].CGColor;
        shapeLayer.lineCap = kCALineCapRound;
        shapeLayer.lineJoin = kCALineJoinRound;
        shapeLayer.lineWidth = 3.0f;
    }
    return self;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    CGPoint point = [[touches anyObject] locationInView:self];
    [self.bezierPath moveToPoint:point];
}

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    CGPoint point = [[touches anyObject] locationInView:self];
    [self.bezierPath addLineToPoint:point];
    ((CAShapeLayer *)self.layer).path = self.bezierPath.CGPath;
}



@end
